##############################################################################
# Filename: Robustness_Affiliation.R
# Purpose: Produce SI Table A6 
##############################################################################

source("Setup.R")
# Set neutral values for those in treatment groups who didn't write a comment
data_eval$CommentBiased[is.na(data_eval$CommentBiased)&data_eval$Article%in%c("DN","DP")] <- 0
data_eval$CommentFeeling[is.na(data_eval$CommentFeeling)&data_eval$Article%in%c("DN","DP")] <- 2

# Models with "Pro-Modi" as the measure of political affiliation
mod_correct_promodi = lm(YesCorrect ~ ProModi*Article 
                        + CollegeGrad + NewsDaily + StrongInterestPolitics,
                        data = data_eval)
mod_ww_promodi = lm(YesWellWritten ~ ProModi*Article 
                   + CollegeGrad + NewsDaily + StrongInterestPolitics,
                   data = data_eval)
mod_recm_promodi = lm(YesRecommend ~ ProModi*Article 
                          + CollegeGrad + NewsDaily + StrongInterestPolitics,
                          data = data_eval)
mod_bias_promodi = lm(CommentBiased ~ ProModi*Article 
                      + CollegeGrad + NewsDaily + StrongInterestPolitics, 
                      data = data_eval) 
mod_feel_promodi = lm(as.numeric(CommentFeeling) ~ ProModi*Article 
                         + CollegeGrad + NewsDaily + StrongInterestPolitics, 
                         data = data_eval) 
mod_dem_promodi = lm(as.numeric(op_dem) ~ ProModi*Article
                     + CollegeGrad + NewsDaily + StrongInterestPolitics,
                     data = data_op)

# Models with "Extreme BJP" as the measure of political affiliation
mod_correct_extremebjp = lm(YesCorrect ~ ExtremeBJP*Article 
                           + CollegeGrad + NewsDaily + StrongInterestPolitics,
                           data = data_eval)
mod_ww_extremebjp = lm(YesWellWritten ~ ExtremeBJP*Article 
                      + CollegeGrad + NewsDaily + StrongInterestPolitics,
                      data = data_eval)
mod_recm_extremebjp = lm(YesRecommend ~ ExtremeBJP*Article 
                             + CollegeGrad + NewsDaily + StrongInterestPolitics,
                             data = data_eval)
mod_bias_extremebjp = lm(CommentBiased ~ ExtremeBJP*Article 
                      + CollegeGrad + NewsDaily + StrongInterestPolitics, 
                      data = data_eval) 
mod_feel_extremebjp = lm(as.numeric(CommentFeeling) ~ ExtremeBJP*Article 
                        + CollegeGrad + NewsDaily + StrongInterestPolitics, 
                        data = data_eval) 
mod_dem_extremebjp = lm(as.numeric(op_dem) ~ ExtremeBJP*Article
                        + CollegeGrad + NewsDaily + StrongInterestPolitics,
                        data = data_op)

# Models with "Prefer BJP" as the measure of political affiliation
mod_correct_preferbjp = lm(YesCorrect ~ PreferBJP*Article 
                          + CollegeGrad + NewsDaily + StrongInterestPolitics,
                          data = data_eval)
mod_ww_preferbjp = lm(YesWellWritten ~ PreferBJP*Article 
                     + CollegeGrad + NewsDaily + StrongInterestPolitics,
                     data = data_eval)
mod_recm_preferbjp = lm(YesRecommend ~ PreferBJP*Article 
                            + CollegeGrad + NewsDaily + StrongInterestPolitics,
                            data = data_eval)
mod_bias_preferbjp = lm(CommentBiased ~ PreferBJP*Article 
                         + CollegeGrad + NewsDaily + StrongInterestPolitics, 
                         data = data_eval) 
mod_feel_preferbjp = lm(as.numeric(CommentFeeling) ~ PreferBJP*Article 
                        + CollegeGrad + NewsDaily + StrongInterestPolitics, 
                        data = data_eval) 
mod_dem_preferbjp = lm(as.numeric(op_dem) ~ PreferBJP*Article
                       + CollegeGrad + NewsDaily + StrongInterestPolitics,
                       data = data_op)

# Print
starpan1 = stargazer(mod_correct_promodi, mod_ww_promodi, mod_recm_promodi, mod_bias_promodi, mod_feel_promodi, mod_dem_promodi,
                     align=TRUE, keep.stat="n", no.space=TRUE,
                     covariate.labels=c("Pro-Modi",
                                        "Negative Article","Positive Article",
                                        "College Graduate", "Daily News", "Interested in Politics",
                                        "Pro-Modi x Negative Article","Pro-Modi x Positive Article"))
starpan2 = stargazer(mod_correct_extremebjp, mod_ww_extremebjp, mod_recm_extremebjp, mod_bias_extremebjp, mod_feel_extremebjp, mod_dem_extremebjp,
                     align=TRUE, keep.stat="n", no.space=TRUE,
                     covariate.labels=c("Extreme BJP",
                                        "Negative Article","Positive Article",
                                        "College Graduate", "Daily News", "Interested in Politics",
                                        "Extreme BJP x Negative Article","Extreme BJP x Positive Article"))
starpan3 = stargazer(mod_correct_preferbjp, mod_ww_preferbjp, mod_recm_preferbjp, mod_bias_preferbjp, mod_feel_preferbjp, mod_dem_preferbjp,
                     align=TRUE, keep.stat="n", no.space=TRUE,
                     covariate.labels=c("Prefer BJP",
                                        "Negative Article","Positive Article",
                                        "College Graduate", "Daily News", "Interested in Politics",
                                        "Prefer BJP x Negative Article","Prefer BJP x Positive Article"))
starpans <- star_panel(starpan1, starpan2, starpan3, 
                       panel.names = c("","",""))
paste(starpans, collapse = '\n') %>% cat()